﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using PluginFramework.Packages;
using Xunit;

namespace PluginTests.PackageTests
{
	public class XmlPackageSettingsTests
	{
		public const string PathDir = @"..\..\PackageTests\XmlSettingsProvider";
		private readonly XmlPackageSettingsProvider _provider;
		private Stopwatch _t = new Stopwatch();

		public XmlPackageSettingsTests()
		{
			_provider = new XmlPackageSettingsProvider(PathDir);
			File.Copy(Path.Combine(PathDir, "packages-test.xml"), Path.Combine(PathDir, "packages.xml"), true);
		}


		[Fact]
		public void read_settings()
		{
			var rez = new[] {"Dir1", "AltDir"};
			Assert.Equal(rez, _provider.ReadPackageList().ToArray());
		}

		[Fact]
		public void file_missing_returns_empty_list()
		{
			File.Delete(Path.Combine(PathDir, "packages.xml"));
			IEnumerable<string> list = _provider.ReadPackageList();
			Assert.Empty(list);
		}

		[Fact]
		public void write_settings()
		{
			var rez = new[] {"MyPlugin"};
			_provider.WritePackageList(rez);
			Assert.Equal(rez, _provider.ReadPackageList().ToArray());
		}

		private void Write(string format, params object[] param)
		{
			Console.WriteLine(format, param);
		}
	}
}